package com.sky.com.sky.web.app;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    OrderService orderService;


    /**
     * 下单
     * @param ordersSubmitDTO
     * @return
     * **/
    @PostMapping("/submit")
    public Result submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     * @param ordersPaymentDTO
     * @deprecated
     * **/
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付: {}",ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单: {}",orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    /**
     * 历史订单查询
     * @param page
     * @param pageSize
     * @param status 订单状态
     * @return
     * **/
    @GetMapping("/historyOrders")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "1") Integer pageSize,
                       Integer status){
        PageResult pageResult=orderService.pageQuery4User(page,pageSize,status);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     * @param id
     * @return
     * **/
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> orderDetail(@PathVariable("id") Long id){
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }

    /**
     * 用户取消订单
     * @return
     * **/
    @PutMapping("/cancel/{orderId}")
    public Result cancel(@PathVariable("orderId") Long orderId){
        orderService.userOrderCancel(orderId);
        return Result.success();
    }

    /**
     * 再来一单
     * @param orderId
     * @return
     * **/
    @PostMapping("/repetition(/{orderId})")
    public Result repetition(@PathVariable Long orderId){
        orderService.repetition(orderId);
        return Result.success();
    }

    /**
     * 用户催单
     * @param orderId
     * @return
     * **/
    @GetMapping("/reminder/{orderId}")
    public Result reminder(@PathVariable("orderId") Long orderId){
        orderService.reminder(orderId);
        return Result.success();
    }
}
